<?php
// 首页显示信息
namespace NewAdmin\Controller;
use Think\Controller;
class FinanceController extends CommonController {
	
	
	public function user_withdrawal(){
		$users_getmoney=M('users_getmoney');
		$where='';
		$status=I('post.status',-1);
		if($status>=0){
			$where=' and yt_users_getmoney.status='.$status;
		}
		$count=$users_getmoney
			->field('yt_users_getmoney.*,yt_users.phone')
			->join('yt_users ON yt_users.id = yt_users_getmoney.uid','left')
			->where('yt_users_getmoney.type=1'.$where)
			->count();
    	$this->assign('counts',$count);
    	$Page = new \Think\Page ($count,15); // 实例化分页类 传入总记录数
		$Page->setConfig('header','条记录');
	    $Page->setConfig('prev','上一页');
	    $Page->setConfig('next','下一页');
		$show = $Page->show(); // 分页显示输出
		$rs=$users_getmoney
			->field('yt_users_getmoney.*,yt_users.phone')
			->join('yt_users ON yt_users.id = yt_users_getmoney.uid','left')
			->where('yt_users_getmoney.type=1'.$where)
			->order('yt_users_getmoney.id desc')
			->limit($Page->firstRow.','.$Page->listRows)
			->select();
		$this->assign('page',$show);

		$this->assign('status',$status);
    	$this->assign('rs',$rs);
    	$this->assign('title','用户提现');
    	$this->display();
    }
    
    public function store_withdrawal(){
		$users_getmoney=M('users_getmoney');
		$where='';
		$status=I('post.status',-1);
		if($status>=0){
			$where=' and yt_users_getmoney.status='.$status;
		}
		$count=$users_getmoney
			->field('yt_users_getmoney.*,yt_store.title')
			->join('yt_store ON yt_store.id = yt_users_getmoney.uid','left')
			->where('yt_users_getmoney.type=2'.$where)
			->count();
		$this->assign('counts',$count);
    	$Page = new \Think\Page ($count,15); // 实例化分页类 传入总记录数
		$Page->setConfig('header','条记录');
	    $Page->setConfig('prev','上一页');
	    $Page->setConfig('next','下一页');
		$show = $Page->show(); // 分页显示输出
		$rs=$users_getmoney
			->field('yt_users_getmoney.*,yt_store.title')
			->join('yt_store ON yt_store.id = yt_users_getmoney.uid','left')
			->where('yt_users_getmoney.type=2'.$where)
			->order('yt_users_getmoney.id desc')
			->limit($Page->firstRow.','.$Page->listRows)
			->select();
		$this->assign('status',$status);
    	$this->assign('rs',$rs);
    	$this->assign('page',$show);
    	$this->assign('title','店铺提现');
    	$this->display();
    }
    
    
    public function user_withdrawal_edit(){
    	$data['id']=I('get.id');
    	$data['status']=I('get.status');
    	$data['reason']=I('get.text','无');
    	$users_getmoney=M('users_getmoney');
    	$users_getmoney->save($data);
    	if($data['status']==2){
    		$rs=M('users_getmoney')->find($data['id']);
    		$log['uid']=$rs['uid'];
    		$log['addtime']=time();
    		$log['money']=$rs['money'];
    		$log['type']=1;
    		$log['other']='提现拒绝，退款,理由：'.$data['reason'];
    		$log['money_type']=1;
    		M('users_log')->add($log);
    		M('users')->where('id='.$rs['uid'])->setInc('money',$rs['money']);
    		$this->ajaxReturn(1);
    	}
    	$this->redirect('Finance/user_withdrawal');
    }
     public function store_withdrawal_edit(){
     	
    	$data['id']=I('get.id');
    	$data['status']=I('get.status');
    	$data['reason']=I('get.text','无');
    	$users_getmoney=M('users_getmoney');
    	$users_getmoney->save($data);
    	if($data['status']==2){
    		$rs=M('users_getmoney')->find($data['id']);
    		$log['store_id']=$rs['uid'];
    		$log['addtime']=time();
    		$log['money']=$rs['money'];
    		$log['type']=1;
    		$log['other']='提现拒绝，退款,理由：'.$data['reason'];
    		$log['money_type']=1;
    		M('store_money_log')->add($log);
    		$this->ajaxReturn(1);
    	}elseif($data['status']==3){
    		$this->ajaxReturn(1);
    	}else{
    		$this->redirect('Finance/store_withdrawal');
    	}
    	
    }
    
    public function store_order_info(){
    	$id=I('get.id');
    	$g_info=M('users_getmoney')->find($id);
    	$store_id=$g_info['uid'];
    	$store_info=M('store')->field('ali_number,ali_name')->find($store_id);
    	$store_info['tixian']=$g_info['money'];
    	$this->ajaxReturn($store_info);
    	
    }
    public function user_order_info(){
    	$id=I('get.id');
    	$g_info=M('users_getmoney')->find($id);
    	$user_id=$g_info['uid'];
    	$user_info=M('users')->field('ali_number,ali_name')->find($user_id);
    	$user_info['tixian']=$g_info['money'];
    	$this->ajaxReturn($user_info);
    	
    }
   
    function backorder(){
    	$where='refund_state>=4';
    	$status=$_GET['status'];
    	if($status>0){
    		if($status==1){
    			$where='refund_state=4';
    		}elseif($status==2){
    			$where='refund_state=5';
    		}
    	}
    	
    	$count=M('order')->where($where)->count();
    	$this->assign('counts',$count);
    	$Page = new \Think\Page ($count,15); // 实例化分页类 传入总记录数
		$Page->setConfig('header','条记录');
	    $Page->setConfig('prev','上一页');
	    $Page->setConfig('next','下一页');
		$show = $Page->show(); // 分页显示输出
    	$backorder=M('order')->where($where)->order('refund_time desc,order_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
    	$this->assign('status',$status);
    	$this->assign('backorder',$backorder);
    	$this->assign('page',$show);
    	$this->assign('title','退款订单');
    	$this->display();
    }
    function backorder_edit(){
    	$data['order_id']=I('get.id');
    	$data['refund_state']=I('get.status');
    	M('order')->save($data);
    }
}